package org.neuedu.vblogvue.service;

import org.neuedu.vblogvue.mapper.UserMapper;
import org.neuedu.vblogvue.model.Role;
import org.neuedu.vblogvue.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class UserService implements UserDetailsService {
   @Autowired
    UserMapper userMapper;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
     User user= userMapper.loadUserByUsername(username);
if(user==null){
    throw new UsernameNotFoundException("没找到");
}
        List<Role> roles =userMapper.getRolesById(user.getId());
user.setRoles(roles);
return user;
    }
}
